// pages/demo/demo.ts

import {getInstanceDetail,GameInstance,Monster,MonsterSkill,MonsterDrop} from "../../../api/game_instance/game_instance"

type TabItem = {
  icon: string;
  activeIcon: string;
  title: string;
}

Page({
  data: {
    instanceId:'',
    // Tab栏配置 ‌:ml-citation{ref="3,4" data="citationList"}
    tabs: [
      {
        icon: "https://wow.shuzhipeixian.com:12812/download/wow_collect/mystic/sys/jinenggongvle.webp",
        activeIcon: "https://wow.shuzhipeixian.com:12812/download/wow_collect/mystic/sys/jinenggongvle.webp",

        title: "攻略"
      },
      {
        icon: "https://wow.shuzhipeixian.com:12812/download/wow_collect/mystic/sys/diaoluo.webp",
        activeIcon: "https://wow.shuzhipeixian.com:12812/download/wow_collect/mystic/sys/diaoluo.webp",
        title: "掉落"
      },
      {
        icon: "https://wow.shuzhipeixian.com:12812/download/wow_collect/mystic/sys/cizhui.webp",
        activeIcon: "https://wow.shuzhipeixian.com:12812/download/wow_collect/mystic/sys/cizhui.webp",
        title: "词缀"
      }
    ] as TabItem[],
    currentTabIndex: 0,
    instanceData:{} as GameInstance,
   
  },
 /**
  * 生命周期函数--监听页面加载
  */
 onLoad(option: any) {
    console.log(option)
    this.setData({
      instanceId: option.id
    })
    this.loadData()
  },
  handleImagePreview(e:any){
    // console.log("图片预览",e)
    const url = e.currentTarget.dataset.url;
    let urls=[url]
    wx.previewImage(
      {
        current: url, 
        urls: urls ,
        showmenu:false
      }
    );
  },
  async loadData(){
    let res = await getInstanceDetail(this.data.instanceId);
    this.setData({
      instanceData:res.data
    })
    console.log(this.data.instanceData)
  },
  // Tab切换处理 ‌:ml-citation{ref="1,2" data="citationList"}
  handleTabTap(e: WechatMiniprogram.TapEvent) {
    const index = e.currentTarget.dataset.index;
    this.setData({ currentTabIndex: index });
    // 这里可添加对应tab的数据加载逻辑
  },
  showSkill(e:any){
    var currentValue = this.data.instanceData.monsterList[e.currentTarget.dataset.index].showSkillFlag;
    var key = "instanceData.monsterList[" + e.currentTarget.dataset.index + "].showSkillFlag"; //这里必须这样拼接
    //因为小程序中分有逻辑层和渲染层等。所以我们需要用setdata函数，渲染到视图界面。
    this.setData({ //异步刷新，就是渲染
    //这里进行赋值
      [key]: !currentValue
    })
  }
})
